{{ define "admin/goodsCate/add.html" }}
{{ template "admin/common/page_header.html" .}}
<link href="/static/ly/js/lyear-dropdowntree/dropdowntree.css" rel="stylesheet">


<div class="container-fluid p-t-15">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-body">
                    <form action="/admin/goodsCate/doAdd" method="post" enctype="multipart/form-data">

                        <div class="form-group row">
                            <label class="col-sm-2 control-label" for="title">分类名称</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="title" name="title" value="" placeholder="请输入标题">
                            </div>
                        </div>


                        <div class="form-group row">
                            <label class="col-sm-2 control-label">上级分类</label>
                            <input type="hidden" name="pid" id="pid" />
                            <div class="lyear-dropdown-tree col-sm-10">
                                <input type="text" class="form-control" value="" placeholder="请选择上级分类" data-toggle="dropdown">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label" for="cate_img">分类图片</label>
                            <div class="col-sm-10">
                                <input type="file" class="form-control" id="cate_img" name="cate_img" >
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label" for="link">跳转地址</label>
                            <div class="col-sm-10">
                                <input type="text" name="link" class="form-control" id="link"/>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label" for="template">分类模板</label>
                            <div class="col-sm-10">
                                <input type="text" name="template" class="form-control" id="template" placeholder="空表示默认模板" />
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label" for="sub_title">Seo标题</label>
                            <div class="col-sm-10">
                                <input type="text" name="sub_title" class="form-control" id="sub_title" placeholder="Seo标题" />
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label" for="keywords">Seo关键词</label>
                            <div class="col-sm-10">
                                <input type="text" name="keywords" class="form-control" id="keywords" placeholder="Seo关键词" />
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label" for="description">Seo关键词</label>
                            <div class="col-sm-10">
                                <textarea type="text" name="description" class="form-control" id="description" rows="4" placeholder="Seo关键词" ></textarea>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label" for="sort">排　　序</label>
                            <div class="col-sm-10">
                                <input type="text" name="sort" class="form-control" id="sort" value="10" />
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label" for="status">状　　态</label>
                            <div class="col-sm-10">
                                <div class="clearfix">
                                    <div class="custom-control custom-radio custom-control-inline">
                                        <input type="radio" id="statusOne" name="status" class="custom-control-input" checked value="1">
                                        <label class="custom-control-label" for="statusOne">显示</label>
                                    </div>
                                    <div class="custom-control custom-radio custom-control-inline">
                                        <input type="radio" id="statusTwo" name="status" class="custom-control-input" value="0">
                                        <label class="custom-control-label" for="statusTwo">隐藏</label>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group col-md-12">
                            <button type="submit" class="btn btn-primary ajax-post" target-form="add-form">确 定</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript" src="/static/ly/js/lyear-dropdowntree/bootstrap.lyear.dropdowntree.min.js"></script>
    <script>


        $(function (){

            var treeData = {{.goodsCateList}}
            var data = BuildData(treeData)

            var test = $('.lyear-dropdown-tree').lyearDropdownTree({
                data : data,                    // 树状结构数据
                multiSelect : false,             // 是否多选，默认true
                jsonStr : ',',                  // 数据分割符，默认','，例如获取选中数据会返回：1,2,3
                selectedData : [],              // 当前已选中的数据，默认[]
                relationParent : true,          // 是否关联父类(主要用于多选)，默认true，设置为false，则选中父类，子类不会选中
                relationChildren : true,        // 是否关联子类(主要用于多选)，默认true，设置为false，则子类全部选中，父类不会选中

                //选中回调
                checkHandler: function(el) {    // 回调
                    console.log(el);
                    if (test.getSelectedID().length == 0) {
                        console.log("你没有做出选择")
                    } else {
                       console.log(test.getSelectedID())
                        $("#pid").val(test.getSelectedID())
                    }
                },
            });

        })

        /**
         * 构建tree所需数据
         * @param treeData
         * @returns {*[]}
         * @constructor
         */
        function BuildData(treeData){
            let dataArr = []
            for (let item of treeData) {
                let obj = {}
                obj.title = item.Title
                obj.id = item.Id
                obj.children = []
                console.log(obj)
                dataArr.push(obj)
            }
            return dataArr
        }



    </script>

{{end}}